package com.dingqb.ktdemo.base


fun main(args: Array<String>) {
    //类型后面加?表示可为空
    var age: String? = "101"
//抛出空指针异常
    val ages = age!!.toInt()
//不做处理返回 null
    val ages1 = age?.toInt()
//age为空返回-1
    val ages2 = age?.toInt() ?: -1

    println(ages);
    println(ages1);
    println(ages2);
    println("age==${age}");
    var a = 10.0;
    var b = 10;
    println(a == b.toDouble());
    if (a.toInt() == 10 || b == 10) {

    }
    var x: Int = 11;
    when (x) {
        in 1..9 -> println("when (x) in 1..9-> println()");
        10 -> println("x==10");
        else -> println("x>10");
    }
    var list = listOf(11, 22, 33);
    for (i in list) {
        println(i);
    }
    for (i in list.indices) {
        println("index==" + i.toString() + ", value==" + list[i]);

    }

    var emm = empty("constructor");
    var emm2 = empty("constructor2");
    println(emm == emm2);
    emm.name = "ding"
    println(emm.name);
    println(emm.lastName);

}

class empty constructor(var coo: String) {
    constructor(coo: String, age: Int) : this(coo) {
        print(coo);
        print(age);
    }

    init {
        println("$coo");
    }

    var name: String = "ding"
        get() = field.toUpperCase();
        set(value) {
            if (value == "ding")
                field = "dingqb"
            else field = value;
        }

    var lastName: String = "zhang"
        get() = field.toUpperCase()   // 将变量赋值后转换为大写
        set

}
